package org.dromara.learning_xq.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.dromara.learning_xq.entity.AsExaminationManagement;
import org.dromara.learning_xq.service.AsExaminationManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("asExaminationManagement")
@Tag(name = "考试管理")
public class AsExaminationManagementController {


    @Autowired
    private AsExaminationManagementService asExaminationManagementService;

    @Operation(summary = "查询所有考试")
    @GetMapping("/selectAsExaminationManagementAll")
    public ResponseEntity<Map<String, Object>> selectAsExaminationManagementAll() {
        // 初始化响应对象
        Map<String, Object> response = new HashMap<>();
        try {
            // 调用服务层方法查询所有考试信息
            List<AsExaminationManagement> exams = asExaminationManagementService.selectAsExaminationManagementAll();
            // 将查询结果放入响应对象中
            response.put("data", exams);
            // 设置成功消息和状态码
            response.put("message", "查询成功");
            response.put("status", HttpStatus.OK.value());
            // 返回成功响应
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            // 设置失败消息和状态码
            response.put("message", "查询失败");
            response.put("status", HttpStatus.INTERNAL_SERVER_ERROR.value());
            // 返回失败响应
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
        }
    }

    @Operation(summary = "根据条件查询考试")
    @GetMapping("/selectAsViewingJobsCondition")
    public ResponseEntity<Map<String, Object>> selectAsViewingJobsCondition(
        @RequestParam(value = "state", required = false) String state,
        @RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "subjectTeacher", required = false) String subjectTeacher) {

        // 响应体，用于返回查询结果
        Map<String, Object> response = new HashMap<>();
        try {
            // 调用服务层的方法进行条件查询
            List<AsExaminationManagement> exams = asExaminationManagementService.selectAsViewingJobsCondition(state, name, subjectTeacher);

            // 查询成功，填充响应数据
            response.put("data", exams);
            response.put("message", "查询成功");
            response.put("status", HttpStatus.OK.value());
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            // 查询失败，填充响应数据
            response.put("message", "查询失败");
            response.put("status", HttpStatus.INTERNAL_SERVER_ERROR.value());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
        }
    }


}
